package com.william.xiaobujiantest;

import android.Manifest;
import android.app.AlertDialog;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;

//TODO 如果打开了mainActivity，然后通过第三方工具或系统自己的工具释放内存，会直接杀死进程，之后常驻service也无法重启，这里需要找一下解决办法！！！
public class MainActivity extends AppCompatActivity {

    //我晕
    @BindView(R.id.tv)
    TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        this.tv.setText((new Date().toString()));

        //=============获取经纬度===================================
        //申请权限
        boolean LocationPermissionDenied = getIntent().getBooleanExtra("LocationPermissionDenied",false);
        if(LocationPermissionDenied) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
                            Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
        }

    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {

        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        //靠，其实不管设置中怎么搞授权，都会进这个方法，也就是说每次程序都会申请权限，而设置中心只不过记录了你的习惯而自动去对linux底层授权了而已
        Toast.makeText(this,"反正还是进我这了",Toast.LENGTH_SHORT).show();
        if(grantResults[0] != PackageManager.PERMISSION_GRANTED ||
                grantResults[1] != PackageManager.PERMISSION_GRANTED){

            new  AlertDialog.Builder(this)
                    .setTitle("提示" )
                    .setMessage("本功能需要访问位置权限，用来获取手机位置，并提供相应的天气状况！" )
                    .setPositiveButton("确定",null).show();
        }
    }
}
